//
//  UIButton+Extension.m
//  Practice
//
//  Created by yons on 14.8.20.
//  Copyright © 2020 yons. All rights reserved.
//

#import "UIButton+Extension.h"
#import "UIImage+SMExtension.h"

@implementation UIButton (Extension)

/// type+图片名
/// @param buttonType 类型
/// @param named 图片名称
+ (UIButton *)buttonWithType:(UIButtonType)buttonType normalImageNamed:(NSString *)named {
    UIButton *button = [UIButton buttonWithType:buttonType];
    [button setImage:[UIImage imageNamed:named] forState:UIControlStateNormal];
    return button;
}

/// type+图片名+高亮
/// @param buttonType 类型
/// @param named 图片名称
/// @param selectNamed 高亮图片名称
+ (UIButton *)buttonWithType:(UIButtonType)buttonType normalImageNamed:(NSString *)named selectImageNamed:(NSString *)selectNamed {
    UIButton *button = [self buttonWithType:buttonType normalImageNamed:named];
    [button setImage:[UIImage imageNamed:selectNamed] forState:UIControlStateSelected];
    return button;
}

/// type+图片名+target+方法+事件
/// @param buttonType 类型
/// @param named 图片名称
/// @param target target
/// @param action action
/// @param controlEvents controlEvents
+ (UIButton *)buttonWithType:(UIButtonType)buttonType normalImageNamed:(NSString *)named addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents {
    UIButton *button = [self buttonWithType:buttonType normalImageNamed:named];
    [button addTarget:target action:action forControlEvents:controlEvents];
    return button;
}

/// type+图片名+高亮+target+方法+事件
/// @param buttonType 类型
/// @param named 图片名称
/// @param selectNamed 高亮图片名称
/// @param target target
/// @param action action
/// @param controlEvents controlEvents
+ (UIButton *)buttonWithType:(UIButtonType)buttonType normalImageNamed:(NSString *)named selectImageNamed:(NSString *)selectNamed addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents {
    UIButton *button = [self buttonWithType:buttonType normalImageNamed:named selectImageNamed:selectNamed];
    [button addTarget:target action:action forControlEvents:controlEvents];
    return button;
}

/// (路径)type+图片名
/// @param buttonType type
/// @param named 图片名称
+ (UIButton *)buttonWithType:(UIButtonType)buttonType normalImageContentsOfFileNamed:(NSString *)named {
    UIButton *button = [UIButton buttonWithType:buttonType];
    [button setImage:[UIImage sm_imageWithNamed:named] forState:UIControlStateNormal];
    return button;
}

/// (路径)type+图片名+高亮
/// @param buttonType type
/// @param named 图片名
/// @param selectNamed 高亮图片名
+ (UIButton *)buttonWithType:(UIButtonType)buttonType normalImageContentsOfFileNamed:(NSString *)named selectImageContentsOfFileNamed:(NSString *)selectNamed {
    UIButton *button = [self buttonWithType:buttonType normalImageContentsOfFileNamed:named];
    [button setImage:[UIImage sm_imageWithNamed:selectNamed] forState:UIControlStateSelected];
    return button;
}

/// type +文本+文本颜色+文本大小
/// @param buttonType type
/// @param text 文本
/// @param textColor 文本颜色
/// @param size 文本大小
+ (UIButton *)buttonWithType:(UIButtonType)buttonType text:(NSString *)text textColor:(UIColor *)textColor fontSize:(CGFloat)size weight:(UIFontWeight)weight {
    UIButton *button = [UIButton buttonWithType:buttonType];
    button.titleLabel.font = [UIFont systemFontOfSize:size weight:weight];
    [button setTitle:text forState:UIControlStateNormal];
    [button setTitleColor:textColor forState:UIControlStateNormal];
    return button;
}

/// type+文本+文本颜色+文本大小+target+方法+事件
/// @param buttonType type
/// @param text 文本
/// @param textColor 文本颜色
/// @param size 文本大小
/// @param target target
/// @param action 方法
/// @param controlEvents 事件
+ (UIButton *)buttonWithType:(UIButtonType)buttonType text:(NSString *)text textColor:(UIColor *)textColor fontSize:(CGFloat)size weight:(UIFontWeight)weight addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents {
    UIButton *button = [self buttonWithType:buttonType text:text textColor:textColor fontSize:size weight:weight];
    [button addTarget:target action:action forControlEvents:controlEvents];
    return button;
}


/// type+文本+文本颜色+文本大小+剪切半径
/// @param buttonType type
/// @param text 文本
/// @param textColor 文本颜色
/// @param size 文本大小
/// @param radius 剪切半径
+ (UIButton *)buttonWithType:(UIButtonType)buttonType text:(NSString *)text textColor:(UIColor *)textColor fontSize:(CGFloat)size weight:(UIFontWeight)weight radius:(CGFloat)radius {
    UIButton *button = [self buttonWithType:buttonType text:text textColor:textColor fontSize:size weight:weight];
    button.layer.cornerRadius = radius;
    button.clipsToBounds = YES;
    return button;
}

/// type+文本+文本颜色+文本大小+剪切半径+target+方法+事件
/// @param buttonType type
/// @param text 文本
/// @param textColor 文本颜色
/// @param size 文本大小
/// @param radius 剪切半径
/// @param target target
/// @param action 方法
/// @param controlEvents 事件
+ (UIButton *)buttonWithType:(UIButtonType)buttonType text:(NSString *)text textColor:(UIColor *)textColor fontSize:(CGFloat)size weight:(UIFontWeight)weight radius:(CGFloat)radius addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents {
    UIButton *button = [self buttonWithType:buttonType text:text textColor:textColor fontSize:size weight:weight radius:radius];
    [button addTarget:target action:action forControlEvents:controlEvents];
    return button;
}

/// type+文本+文本颜色+文本大小+剪切半径+边框宽度+边框颜色
/// @param buttonType type
/// @param text 文本
/// @param textColor 文本颜色
/// @param size 文本大小
/// @param radius 剪切半径
/// @param borderWidth 边框宽度
/// @param borderColor 边框颜色
+ (UIButton *)buttonWithType:(UIButtonType)buttonType text:(NSString *)text textColor:(UIColor *)textColor fontSize:(CGFloat)size weight:(UIFontWeight)weight radius:(CGFloat)radius borderWidth:(CGFloat)borderWidth borderColor:(UIColor *)borderColor {
    UIButton *button = [self buttonWithType:buttonType text:text textColor:textColor fontSize:size weight:weight radius:radius];
    button.layer.borderWidth = borderWidth;
    button.layer.borderColor = borderColor.CGColor;
    return button;
}

/// type+文本+文本颜色+文本大小+剪切半径+边框宽度+边框颜色+target+方法+事件
/// @param buttonType type
/// @param text 文本
/// @param textColor 文本颜色
/// @param size 文本大小
/// @param radius 剪切半径
/// @param borderWidth 边框宽度
/// @param borderColor 边框颜色
/// @param target target
/// @param action 方法
/// @param controlEvents 事件
+ (UIButton *)buttonWithType:(UIButtonType)buttonType text:(NSString *)text textColor:(UIColor *)textColor fontSize:(CGFloat)size weight:(UIFontWeight)weight radius:(CGFloat)radius borderWidth:(CGFloat)borderWidth borderColor:(UIColor *)borderColor addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents {
    UIButton *button = [self buttonWithType:buttonType text:text textColor:textColor fontSize:size weight:weight radius:radius borderWidth:borderWidth borderColor:borderColor];
    [button addTarget:target action:action forControlEvents:controlEvents];
    return button;
}

@end
